/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.leospa.main;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileWriter;
import java.net.MalformedURLException;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JRootPane;
import javax.swing.Timer;

import com.leospa.clients.SerialClient;
import com.leospa.properties.ColorPropertiesFile;
import com.leospa.properties.ConfigPropertiesFile;
import com.leospa.properties.ContentPropertiesFile;

/**
 *
 * @author ADMIN
 */
public class ConfirmationScreen {

	/**
	 * Creates new form ConfirmationScreen
	 */
	int count = 0;
	MainScreen mainScreen;
	javax.swing.GroupLayout layout;

	public ConfirmationScreen(MainScreen mainScreen, javax.swing.GroupLayout layout) {
		this.layout = layout;
		this.mainScreen = mainScreen;
		// try {
		// URL imgURL = new File( "./images/backgrond.png" ).toURI().toURL();
		// mainScreen.setContentPane(new JLabel(new ImageIcon(imgURL)));
		// } catch (MalformedURLException e) {
		// // TODO Auto-generated catch block
		// if(ConfigPropertiesFile.DEBUG_MODE_ON == true){
		// }
		
		initComponents();
		startTimer();
		jLabel1.setText(ContentPropertiesFile.Confirmation);
		jLabel2.setText(ContentPropertiesFile.Confirmation_Meaasge);
		// SerialClient.getCardSerialNumber();
	}

	public void startTimer() {
		timer = new Timer(1000, new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				count++;
				if (count % ConfigPropertiesFile.CARD_READ_DELAY == 0)
				{
					if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println("Call Card Read==== After 5 second");}
					String carderialNumber = SerialClient.getCardSerialNumber();
					if(ConfigPropertiesFile.DEBUG_MODE_ON == true){System.out.println("Card Serial Number: "+carderialNumber);}
					if(carderialNumber != null)
					{
						Util.getUtilInstance().setRf_id_card_number(carderialNumber);
						timer.stop();
						if (carderialNumber != null)
						{
							jPanel1.setVisible(false);
							LoadingScreen loadingScreen = new LoadingScreen(mainScreen, layout);
							loadingScreen.setLayout();
							// ConfirmationScreen.this.dispose();
						}
					}

					if(ConfigPropertiesFile.DEMO_MODE == true)
					{
						timer.stop();
						Util.getUtilInstance().setRf_id_card_number("C569647F");
						jPanel1.setVisible(false);
						LoadingScreen loadingScreen = new LoadingScreen(mainScreen, layout);
						loadingScreen.setLayout();
						// ConfirmationScreen.this.dispose();
					}
				}
				if (count == 30) {
					timer.stop();
					// new LeoSpaMainFrame(mainScreen ,layout).setVisible(true);
					// ConfirmationScreen.this.dispose();
					MainScreen leoSpaMainFrame = new MainScreen();
					leoSpaMainFrame.setVisible(true);
					mainScreen.dispose();
				}
			}
		});
		timer.setRepeats(true); // Only execute once
		timer.start(); // Go go go!

	}

	Timer timer = null;

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		jDialog1 = new javax.swing.JDialog();
		jPanel1 = new javax.swing.JPanel();
		jPanel2 = new javax.swing.JPanel();
		jLabel1 = new javax.swing.JLabel();
		jLabel2 = new javax.swing.JLabel();
		jButton1 = new javax.swing.JButton();

		javax.swing.GroupLayout jDialog1Layout = new javax.swing.GroupLayout(jDialog1.getContentPane());
		jDialog1.getContentPane().setLayout(jDialog1Layout);
		jDialog1Layout.setHorizontalGroup(jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGap(0, 400, Short.MAX_VALUE));
		jDialog1Layout.setVerticalGroup(jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGap(0, 400, Short.MAX_VALUE));

		jPanel1.setMaximumSize(new java.awt.Dimension(800, 1280));
		jPanel1.setMinimumSize(new java.awt.Dimension(800, 1280));
		jPanel1.setOpaque(false);
		jPanel1.setPreferredSize(new java.awt.Dimension(800, 1280));

		Color color = Color.decode(ColorPropertiesFile.Popup_BG_Color);
		jPanel2.setBackground(color);
		jPanel2.setPreferredSize(new java.awt.Dimension(786, 768));

		color = Color.decode(ColorPropertiesFile.Popup_Header_BG_Color);
		jLabel1.setBackground(color);
		jLabel1.setFont(new java.awt.Font("SansSerif", 1, 48)); // NOI18N
		color = Color.decode(ColorPropertiesFile.Popup_Text_Color);
		jLabel1.setForeground(color);
		jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
		jLabel1.setText(ContentPropertiesFile.Confirmation);
		jLabel1.setOpaque(true);

		jLabel2.setFont(new java.awt.Font("SansSerif", 0, 45)); // NOI18N
		jLabel2.setForeground(color);
		jLabel2.setText(ContentPropertiesFile.Confirmation_Meaasge);
		jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

		try {
			URL imgURL = new File("./images/3.png").toURI().toURL();
			jButton1.setIcon(new javax.swing.ImageIcon(imgURL)); // NOI18N
		} catch (MalformedURLException e) {
			if(ConfigPropertiesFile.DEBUG_MODE_ON == true){e.printStackTrace();}
		}
		jButton1.setOpaque(false);
		jButton1.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				timer.stop();
				// new LeoSpaMainFrame(mainScreen,layout).setVisible(true);
				// ConfirmationScreen.this.dispose();
				MainScreen leoSpaMainFrame = new MainScreen();
				leoSpaMainFrame.setVisible(true);
				mainScreen.dispose();
			}
		});
		
		javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(0, 58, Short.MAX_VALUE)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 639, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(96, 96, 96)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 555, Short.MAX_VALUE)
                        .addContainerGap())))
        );
		
		javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
		jPanel1.setLayout(jPanel1Layout);
		jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(jPanel1Layout.createSequentialGroup().addGap(0, 0, 0)
						.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE,
								javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addContainerGap(150, Short.MAX_VALUE)));
		jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(jPanel1Layout.createSequentialGroup().addGap(0, 0, 0)
						.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE,
								javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addContainerGap(730, Short.MAX_VALUE)));

	}// </editor-fold>

	public void setLayout() {
		layout = new javax.swing.GroupLayout(mainScreen.getContentPane());
		mainScreen.getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				javax.swing.GroupLayout.Alignment.TRAILING,
				layout.createSequentialGroup().addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
								javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addGap(105, 105, 105)));
		layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				javax.swing.GroupLayout.Alignment.TRAILING,
				layout.createSequentialGroup().addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
								javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addGap(94, 94, 94)));

		mainScreen.pack();
	}

	private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

		// this.dispose();
		// new LoadingScreen().setVisible(true);
	}

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String args[]) {
		/* Set the Nimbus look and feel */
		// <editor-fold defaultstate="collapsed" desc=" Look and feel setting
		// code (optional) ">
		/*
		 * If Nimbus (introduced in Java SE 6) is not available, stay with the
		 * default look and feel. For details see
		 * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.
		 * html
		 */
		try {
			for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
				if ("Nimbus".equals(info.getName())) {
					javax.swing.UIManager.setLookAndFeel(info.getClassName());
					break;
				}
			}
		} catch (ClassNotFoundException ex) {
			java.util.logging.Logger.getLogger(ConfirmationScreen.class.getName()).log(java.util.logging.Level.SEVERE,
					null, ex);
		} catch (InstantiationException ex) {
			java.util.logging.Logger.getLogger(ConfirmationScreen.class.getName()).log(java.util.logging.Level.SEVERE,
					null, ex);
		} catch (IllegalAccessException ex) {
			java.util.logging.Logger.getLogger(ConfirmationScreen.class.getName()).log(java.util.logging.Level.SEVERE,
					null, ex);
		} catch (javax.swing.UnsupportedLookAndFeelException ex) {
			java.util.logging.Logger.getLogger(ConfirmationScreen.class.getName()).log(java.util.logging.Level.SEVERE,
					null, ex);
		}
		// </editor-fold>
		// </editor-fold>
		// new ConfirmationScreen().setVisible(true);
		/* Create and display the form */
		// java.awt.EventQueue.invokeLater(new Runnable() {
		// public void run() {
		//
		// }
		// });
	}

	// Variables declaration - do not modify
	private javax.swing.JButton jButton1;
	private javax.swing.JDialog jDialog1;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JPanel jPanel1;
	private javax.swing.JPanel jPanel2;
	// End of variables declaration
}
